home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 128 18 / q18.d81 / t.zero page 18 < prev    next >
Text File  |  2022-08-28  |  9KB  |  187 lines

  1.  
  2.                  ZERO PAGE: AN ALMOST FOOLPROOF INPUT ROUTINE
  3.  
  4.                                by Fender Tucker
  5.  
  6.  
  7.      Here I go again, acting as if I'm some sort of master programmer for
  8. the C-128.  Last issue I talked about a routine that displays a disk's
  9. directory in a menu so the user could choose a file without having to type
  10. or remember anything.  It wasn't foolproof but it worked good enough for me
  11. to use it in CRYPTI-CROSTICS this issue.
  12.  
  13.      BASIC 7.0 has so many good features and commands that I haven't gotten
  14. around to using or learning all of them, but it still lacks a decent INPUT
  15. command.  When you want a user to enter something, you, as a programmer, and
  16. I, as an editor, don't want anything to go wrong.  If you use the INPUT
  17. command there's no telling what may happen.  For instance, your program has
  18. this line
  19.  
  20. 10 INPUTA$
  21.  
  22.  (1) The user presses CRSR UP or DOWN.  The user may end up typing all over
  23. your nice screen.  If he moves the cursor back into place before entering
  24. his string he picks up the question mark as part of his string!
  25.  
  26.  (2) The user presses HOME or CLR.  Either the cursor ends up in the home
  27. position or your beautiful screen is gone.
  28.  
  29.  (3) The user keeps typing like a damn fool and scrolls the screen or messes
  30. up the next screen line.
  31.  
  32.  (4) The user uses DELete and backs up over the question mark.  If he backs
  33. up to the screen line above, your program will get a string that's 80 or so
  34. characters long.
  35.  
  36.      From an esthetic point of view INPUT is a loser, also, since it assumes
  37. your prompt is a question.  Let's face it, we don't want any INPUT commands
  38. in LOADSTAR prpograms.
  39.  
  40.      The only thing INPUT has going for it is that it's easy for the
  41. programmer to implement.  My method (which is almost foolproof) takes a
  42. little programming to do but once you've got the routine done, you can save
  43. it as an ASCII file or program, then append it to your program.
  44.  
  45.  CALLING THE ROUTINE
  46.  -------------------
  47.  
  48.      Whenever you are tempted to use INPUT PQ$, use this instead:
  49.  
  50.      lq=16:window38,22,38+lq,22,1:pq$=f$:gosub30000
  51.  
  52. This will put the cursor at tab 38 on line 22 and will limit the input to 16
  53. characters.  If f$ is already defined, it will be placed in the input window
  54. as a default and the cursor will be placed in the space right after it.  In
  55. my opinion, this is the easiest way to display a default string for the user
  56. to accept as is, or modify.  If you want a prompt, position it in the proper
  57. place right BEFORE the start of the window.
  58.  
  59.      Say your program is working with f$ = "test" and it's time for the user
  60. to save his file (f$).  If the user wants to keep "test" as a filename, the
  61. name is displayed and the user just has to hit RETURN to accept "test".  If
  62. he wants to save it under another name, he either DELetes "test" (which is
  63. displayed) or adds on to the "test" name.  A quick way of deleting the
  64. default is to press CLR (SHIFT-HOME).  To move the cursor to the first
  65. character of the input box he can just press HOME.
  66.  
  67.      What you, as the programmer, have to consider is the location of the
  68. input area and the length.  Notice that the second and fourth parameters of
  69. the WINDOW command are the same.  The input window will be just one screen
  70. line high.  LQ is the length of the input field.  The right end of the
  71. window is equal to the left end plus the length of the desired input (38 +
  72. 16).
  73.  
  74.  THE ROUTINE ITSELF
  75.  ------------------
  76.  
  77.      The routine takes up 8 lines of BASIC.  The routine is saved on the
  78. issue as "input.bas" and "input.asc".  I'll explain those later.  The
  79. routine looks like:
  80.  
  81.  30000 printchr$(27)"m"chr$(27)"f":printpq$;:sys52591
  82.  30010 getkeya$:ifa$=chr$(13)then30030:elseifpos(0)=lqthena$="CRSR LEFT]"
  83.  30020 printa$;:goto30010
  84.  30030 sys52639:pq$="":?"[HOME]"spc(lq-1);
  85.  30040 close2:open2,3,2:fori=1tolq:get#2,a$:print"[CRSR LEFT][CRSR LEFT]";:
  86.          ifa$<>" "theneq=lq-i+1:i=lq:next:elsenext
  87.  30050 print"[HOME]";:close2:open2,3,2:fori=1toeq:get#2,a$
  88.  30060 pq$=pq$+a$
  89.  30070 next:close2:print"[HOME][HOME]"chr$(27)"l":return
  90.  
  91. Line 30000 puts the window in the no scroll mode (ESC "m"), makes the cursor
  92. flash (ESC "f"), then prints the default (pq$) with the cursor right after
  93. the end of the default.  The SYS turns the cursor on.
  94.  
  95. Line 30010 gets a character from the keyboard.  If it's RETURN then the
  96. input is over, otherwise it checks to see if the cursor is in the rightmost
  97. space in the window.  If so it makes a$ equal to CRSR LEFT.  This is a
  98. "fudge factor" that was needed because the window is actually one space
  99. larger than LQ.
  100.  
  101. Line 30020 prints the character and goes back to 30010 for another.
  102.  
  103. Line 30030 turns off the flashing cursor, clears pq$, then places the cursor
  104. at the very end of the input box.  The SYS to turn off the cursor is very
  105. important or you'll have trouble with the cursor in the rest of your
  106. program.
  107.  
  108. Line 30040 closes then opens a file to the SCREEN!  Then it inputs a
  109. character, one at a time, moving backward to the end of the input.  This is
  110. just a sneaky way of finding out how long the input string is.  The
  111. 80-column screen is not easy to PEEK so GET#ing the info from the screen is
  112. the easiest way I know of to do this.
  113.  
  114. Lines 30050 - 30070 puts the cursor at the beginning of the input window,
  115. opens a channel to the screen, GET#s whatever is in the window, makes it
  116. into PQ$, closes the channel, disables the window ([HOME][HOME]), re-enables
  117. the scroll (ESC "l") and returns to the calling line.
  118.  
  119.  OVERVIEW
  120.  --------
  121.  
  122.      Until I discovered the two SYSes that turn the cursor on and off this
  123. routine was not very valuable because it was practically impossible to
  124. position the cursor for the rest of the program.  Apparently, once you set a
  125. cursor flashing with ESC "f" you can't turn it off with another ESC code. 
  126. You must use the SYS.
  127.  
  128.      This routine is designed to replace INPUT so it creates a window that
  129. is one screen line high.  You could conceivably use it with a deeper window
  130. by modifying it somewhat.  In fact, the version I use in CRYPTI-CROSTICS is
  131. modified for this purpose.
  132.  
  133.      Adding this routine to your BASIC program is simple if you have
  134. JiffyDOS or some cartridge that allows you to list a file to the screen. 
  135. Just make sure your program doesn't have any code numbered in the 30000
  136. area, then use this command
  137.  
  138.    @d:input.bas
  139.  
  140. with the LOADSTAR disk in the drive.  The seven lines will be read to the
  141. screen where you can enter them by pressing RETURN over each of them.
  142.  
  143.      Some cartridges will read an ASCII file to the screen, but not a
  144. tokenized BASIC file.  It's handy to have an ASCII version of the routine
  145. which you can read with @t: (JiffyDOS), & (WarpSpeed), or ! (Super
  146. Snapshot).  To create an ASCII file of a routine, have the routine in memory
  147. by itself.  List it to make sure that only the routine is there, then enter
  148. the following in the immediate mode:
  149.  
  150.   open2,8,2,"routine name,p,w":cmd2:list
  151.  
  152. The drive will light up and stay lit.  When the disk stops spinning and the
  153. cursor appears, enter on another blank line:
  154.  
  155.   print#2:close2
  156.  
  157.      If you don't have a cartridge or JiffyDOS, then the following little
  158. type-in line will read an ASCII file to the screen.
  159.  
  160.  20 open2,8,2,"filename,p,r":fori=0to1:get#2,a$:printa$;:i=st:next:close2
  161.  
  162.      In my opinion, this is easier than using any append trick because they
  163. usually depend on the routine being added to the END of your program.  This
  164. method allows you to enter the lines anywhere in your program depenaing on
  165. their line numbers.  If you like your routines toward the beginning of your
  166. programs (say between lines 20 and 100), just number them that way before
  167. saving them to disk as ASCII.  If you're really organized you could have all
  168. of your favorite BASIC routines saved as ASCII files with DIFFERENT, yet
  169. consistent, line numbers.  Then you can add as many, or few, routines to
  170. your programs as you need and they won't get in each other's way.
  171.  
  172.      So let's don't see the INPUT routine in programs you send to LOADSTAR. 
  173. Of course BASIC 2.0 doesn't have a WINDOW command so for 64 programs you'll
  174. have to use another method.  LOADSTAR has published dozens of them over the
  175. years.
  176.  
  177.      Finally, why do I call thi